import {defineStore} from "pinia";
import {getHosLevel, getHospital, getHospitalName, getHosRegion} from "@/api/home";

interface HomeType {
    hospital: any,
    totalCount: number,
    hosLevel: any,
    hosRegion: any,
    hospitalNames: any
}

const useHomeStore = defineStore("home", {
    state: (): HomeType => ({
        hospital: {},
        totalCount: 10,
        hosLevel: [],
        hosRegion: [],
        hospitalNames: []
    }),
    actions: {
        async getHospitalData(page: number, limit: number, hosType?: string, districtCode?: string) {
            const result = await getHospital(page, limit, hosType, districtCode)
            this.hospital = result.data
            this.totalCount = result.data.totalElements
        },
        async getHosLevelData(dictCode: string) {
            const res = await getHosLevel(dictCode)
            this.hosLevel = res.data
        },
        async getHosRegionData(cityName: string) {
            const res = await getHosRegion(cityName)
            this.hosRegion = res.data
        },
        async getHospitalNameData(hospitalName: string) {
            const res = await getHospitalName(hospitalName)
            this.hospitalNames = res.data
        },
    }
});

export default useHomeStore
